package demo.config.login;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;
import java.util.Collection;

/**
我个人将验证码以及密码模式封装在一起，所以传入三个参数，通过判断判断短信验证码是否为空来决定采用哪种验证方式，是密码验证还是短信验证码验证，
**/
public class AccountLoginToken extends AbstractAuthenticationToken {
    //用户名
    private final Object principal;
    //密码
    private Object credentials;
    //短信验证码
    private String vcode;
    /**
     * 构建一个没有鉴权的 AccountLoginToken,手机号,密码，验证码
     */
    public AccountLoginToken(Object principal, Object credentials,String vcode) {
        super(null);
        this.principal = principal;
        this.credentials=credentials;
        this.vcode = vcode;
        setAuthenticated(false);
    }
    /**
     * 构建拥有鉴权的 AccountLoginToken
     */
    public AccountLoginToken(Object principal, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        // must use super, as we override
        super.setAuthenticated(true);
    }
    @Override
    public Object getCredentials() {
        return this.credentials;
    }
    @Override
    public Object getPrincipal() {
        return this.principal;
    }
    public String getVcode() {
        return this.vcode;
    }
}
